<?php
/**
 * @name SampleModel
 * @desc sample数据获取类, 可以访问数据库，文件，其它系统等
 * @author root
 */
class AuthorityModel
{
    public function __construct() 
    {
    	$this->db = Yaf_Registry::get('db');
    }

    public function getAuthorityPageInfo($start,$everyPage)
    {
        $sql = "select * from authority limit {$start},{$everyPage}";
    	return $this->db->query($sql);
    }
    
    public function getAllCount()
    {
        $sql="select count(*) as `rows` from `authority` ";
        return $this->db->query($sql);
    }
    
    public function selectAuthority()
    {
        $sql = "select * from authority ";
        return $this->db->query($sql);
    }
    public function selectAuthorityId($id)
    {
        $sql = "select * from authority where authority_id='{$id}'";
        return $this->db->query($sql);
    }

    public function selectGroupAuthority($id)
    {
        $sql = "select * from group_authority where group_id='{$id}' ";
        return $this->db->query($sql);
    }

    public function del($id) 
    {
        $sql = "delete from `authority` where authority_id='{$id}' ";
        return $this->db->query($sql);
    }

    public function add($info) 
    {
        $sql="insert into `authority`(`name`,`module`,`controller`,`action`,`remark`) values('{$info['name']}','{$info["module"]}','{$info['controller']}','{$info["action"]}','{$info["remark"]}')";
        return $this->db->query($sql);
    }

    public function edit($info, $id) 
    {
        $sql = "update `authority` set `name`='{$info['name']}', `module`='{$info['module']}',`controller`='{$info['controller']}', `action`='{$info['action']}',`remark`='{$info['remark']}' WHERE authority_id='{$id}'";
        return $this->db->query($sql);
    }  
}
?>
